#include <stdlib.h>
#include <string.h>
#include "vm_string.h"

char* str_trim(char* str) {
    int start = 0;
    while (str[start] == ' ') {
        start++;
    }
    int end = strlen(str) - 1;
    while (str[end] == ' ') {
        end--;
    }
    int size = end - start + 1;
    char* tmp = (char *) malloc(size + 1);
    strncpy(tmp, str + start, size + 1);
    return tmp;
}

char* str_ltrim(char* str) {
    int start = 0;
    while (str[start] == ' ') {
        start++;
    }
    char* tmp = (char *) malloc(strlen(str) - start + 1);
    strcpy(tmp, str + start);
    return tmp;
}